import 'package:flutter/material.dart';

import 'package:get/get.dart';
import 'package:word_app/app/modules/model/screen_adapter.dart';

import '../controllers/feedback_controller.dart';

class FeedbackView extends GetView<FeedbackController> {
  const FeedbackView({super.key});
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text(
          '意见反馈',
          style: TextStyle(fontWeight: FontWeight.bold, fontSize: 18),
        ),
        centerTitle: true,
      ),
      body: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          Padding(
            padding: const EdgeInsets.all(20),
            child: Row(
              mainAxisAlignment: MainAxisAlignment.spaceBetween,
              children: [
                RichText(
                    text: const TextSpan(
                        text: "问题和意见",
                        style: TextStyle(color: Colors.black54),
                        children: <TextSpan>[
                      TextSpan(
                        text: '*',
                        style: TextStyle(color: Colors.red), // 红色
                      )
                    ])),
              ],
            ),
          ),
          Container(
            height: 150,
            margin: const EdgeInsets.only(left: 20, right: 20),
            padding: const EdgeInsets.only(left: 20, right: 20),
            decoration: BoxDecoration(
                color: Colors.white, borderRadius: BorderRadius.circular(10)),
            child: TextField(
              controller: controller.tfVc,
              minLines: 1,
              maxLines: null,
              maxLength: 100,
              onChanged: (value) {
                controller.tfStr = value;
              },
              decoration: const InputDecoration(
                  hintText: '请填写你的功能建议，感谢你的支持~（必填）', border: InputBorder.none),
            ),
          ),
          Container(
            margin: const EdgeInsets.all(20),
            child: const Text(
              "图片(选填，提供问题截图）",
              textAlign: TextAlign.start,
            ),
          ),
          Obx(() => Container(
              height: ((ScreenAdapterModel.getScreenWidth() - 80) / 3) *
                      ((controller.imgaesArr.length / 3) +
                              (controller.imgaesArr.length % 3 > 0 ? 1 : 0))
                          .toInt() +
                  30,
              width: double.infinity,
              padding: const EdgeInsets.all(10),
              margin: const EdgeInsets.only(left: 20, right: 20),
              decoration: BoxDecoration(
                  color: Colors.white, borderRadius: BorderRadius.circular(10)),
              child: GridView.builder(
                  gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(
                      crossAxisCount: 3,
                      crossAxisSpacing: 10,
                      mainAxisSpacing: 10),
                  itemCount: controller.imgaesArr.length,
                  itemBuilder: (context, index) {
                    return InkWell(
                      onTap: () {
                        if (index == controller.imgaesArr.length - 1) {
                          controller.photoGallery();
                        }
                      },
                      child: controller.imgaesArr[index],
                    );
                  }))),
          Center(
            child: InkWell(
              onTap: () {
                controller.submitData();
              },
              child: Container(
                margin: const EdgeInsets.only(top: 30),
                height: 44,
                width: 280,
                decoration: BoxDecoration(
                    color: const Color.fromARGB(255, 112, 128, 255),
                    borderRadius: BorderRadius.circular(15)),
                child: const Center(
                  child: Text(
                    "提交",
                    style: TextStyle(
                        color: Colors.white, fontWeight: FontWeight.bold),
                  ),
                ),
              ),
            ),
          )
        ],
      ),
    );
  }
}
